package date;

import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateStudy {

//    public static void main(String[] args) {
//
//        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date date = new Date(0L);
//        // java 1970-01-01 08:00:00
//        System.out.println(sf.format(date));
//
//
//        Date now = new Date();
//        System.out.println("当前时间"+now);
//        System.out.println("格式化时间");
//
//        String dateString = sf.format(now);
//        System.out.println("格式化后的时间" + dateString);
//        System.out.println("转化为时间戳:"+now.getTime());
//
//    }

    public static void main(String[] args) {
        String yesterday = LocalDate.now().minusDays(1).toString();
        System.out.println(yesterday);

        String yesterdayStart = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIN).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String yesterdayEnd = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MAX).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        System.out.println("昨天的开始：" + yesterdayStart);
        System.out.println("昨天的结束：" + yesterdayEnd);
        String time1 = "2022.10.1";
        String time2 = "2022.10.11";
        LocalDate date2 = LocalDate.parse(time2,DateTimeFormatter.ofPattern("yyyy.MM.d"));
        LocalDate date1 = LocalDate.parse(time1,DateTimeFormatter.ofPattern("yyyy.MM.d"));
        System.out.println(date1.toString());
        System.out.println(date2.toString());

    }
}
